<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/WEB-INF/jsp/common/navigationRight.jsp" %>
<div class="m2-userCentercommon-bg" style="display: none"></div>
<div class="m2-addConfirm" style="display: none">
    <h3 class="m2-addConfirm-head"><i></i>激活加息券</h3>
    <div class="m2-addConfirmain">
        <div class="m2-addConfirm-ipt">
            <span>加息码：</span>
            <input type="text" placeholder="请输入兑换码" id="reward_code">
        </div>
        <p class="m2-addConfir-psg"></p>
        <div class="m2-addConfirbtn">
            <span class="m2-addConbtn-act">激活</span>
            <span class="m2-addConbtn-can">取消</span>
        </div>
    </div>
</div>
<%@include file="/WEB-INF/jsp/common/head.jsp" %>
<%@include file="/WEB-INF/jsp/common/navigationLeft.jsp" %>

<div class="m2-ticketCon">
    <div class="m2-ticketHead">
        <h3><i class="m2-tickHead-red1"></i>我的加息券</h3>
    </div>
    <div class="m2-recharge-tips" style="margin-bottom:10px;">
        <span class="m2-ticketConfirmbtn">加息券兑换</span>
        <p class="m2-ticPsg-nor">加息券使用</p>
        <ul style="padding-bottom:18px;">
            <li><i class="m2-recharge-tips01"></i><b>投资时根据单笔投资金额选择加息券</b></li>
            <li><i class="m2-recharge-tips02"></i><b>一次投资可使用一个加息券</b></li>
            <li><i class="m2-recharge-tips03"></i><b>加息券过期后将不能使用</b></li>
        </ul>
    </div>

    <div class="m2-ticketHead">
        <h3><i class="m2-tickHead-red2"></i>加息券列表</h3>
    </div>
    <div class="m2-ticSearch">
        <ul>
            <li class="m2-ticSea-tit">加息券状态：</li>
            <li class="m2-ticSea-sel" onclick="showTab(1)"><span>未使用</span></li>
            <li class="m2-ticSea-unsel" onclick="showTab(2)"><span>已使用</span></li>
            <li class="m2-ticSea-unsel" onclick="showTab(3)"><span>已过期</span></li>
        </ul>
    </div>
    <div id="tab1">
        <div class="m2-ticResult">
            <div id="list1" class="m2-ticResult_container">
                <table id="tab-zyf" style="width: 100%;">
                    <tr>
                        <td style="border:1px solid #c0c0c0">增加利息值（%）</td>
                        <td style="border:1px solid #c0c0c0">领取日期</td>
                        <td style="border:1px solid #c0c0c0">过期时间</td>
                        <td style="border:1px solid #c0c0c0">增息时间</td>
                        <td style='border:1px solid #c0c0c0'>限定投资额</td>
                    </tr>
                </table>
            </div>
            <div class="m2-ticTotbottom-add">
                <span id="total1"><i></i>累计可用加息卷：<span id="val-zyf">0</span>个</span>
            </div>
        </div>
        <%--<%@include file="/WEB-INF/jsp/common/rollpage.jsp" %>--%>
        <div class="page-bar">
            <ul class="page-num-ul clearfix">
                <li>共<span class="zyf-totalCount"></span>条记录&nbsp;&nbsp; <span class="zyf-currentPageNo"></span>/<span class="zyf-totalPageCount"></span> 页</li>
                    <a class="zyf-first">首页</a>
                    <a class="zyf-prev">上一页</a>
                    <a class="zyf-second">下一页</a>
                    <a class="zyf-last">最后一页</a>
                &nbsp;&nbsp;
            </ul>
            <span class="page-go-form"><label>跳转至</label>
	     <input type="text" name="inputPage" id="inputPage" class="page-key" />页
	     <button type="button" class="page-btn" onClick='jump_to(document.getElementById("inputPage").value)'>GO</button>
		</span>
        </div>
        <div class="m2-ticMoreadd" id="loadmore1">
            <span onclick='getMore(document.getElementById("sta").innerHTML,1)'>加载更多</span>
        </div>
        <div style="display: none">
            <span id="sta"></span>
            <span id="all"></span>
            <span id="name"></span>
        </div>
    </div>
    <%--<div id="tab2" style="display:none;">
        <div class="m2-ticResult">
            <div id="list2" class="m2-ticResult_container">

            </div>
            <div class="m2-ticTotbottom-add" id="loadmore">
                <span id="total2"><i></i>累计已使用加息卷：0个</span>
            </div>
        </div>
        <div class="m2-ticMoreadd" id="loadmore2">
            <span onclick="getMore(2)">加载更多</span>
        </div>
    </div>
    <div id="tab3" style="display:none;">
        <div class="m2-ticResult">
            <div id="list3" class="m2-ticResult_container">

            </div>
            <div class="m2-ticTotbottom-add">
                <span id="total3"><i></i>累计已过期加息卷：0个</span>
            </div>
        </div>
        <div class="m2-ticMoreadd" id="loadmore3">
            <span onclick="getMore(3)">加载更多</span>
        </div>
    </div>--%>

</div>
<script type="text/javascript">

    //筛选栏点击allow_client_type
    $('.m2-ticSearch ul li').click(function () {
        if ($(this).hasClass('m2-ticSea-unsel')) {
            $(this).addClass('m2-ticSea-sel').removeClass('m2-ticSea-unsel');
            $(this).siblings('.m2-ticSea-sel').addClass('m2-ticSea-unsel').removeClass('m2-ticSea-sel');
        }
    });

    var index = [0, 1, 1, 1];
    var total = [0, 0, 0, 0];
    var async = false;
    getMore(1,1);
    // getMore(2);
    // getMore(3);

    function showTab(index) {
        /*$('#tab1').hide();
        $('#tab2').hide();
        $('#tab3').hide();*/
        /*$('#tab' + index).show();*/
        $('#tab1').show();
        getMore(index,0);
    }
    //日期加上天数得到新日期
    function addDate(date, days) {
        if(days == undefined || days == '') {
            days = 1;
        }
        var date = new Date(date);
        date.setDate(date.getDate() + days);
        var month = date.getMonth() + 1;
        var day = date.getDate();
        var mm = "'" + month + "'";
        var dd = "'" + day + "'";

        //单位数前面加0
        if(mm.length == 3) {
            month = "0" + month;
        }
        if(dd.length == 3) {
            day = "0" + day;
        }

        var time = date.getFullYear() + "-" + month + "-" + day
        return time;
    }

    function getMore(cate,currentPageNo) {
        $.ajax({
            url: '/zyf/showJxj',
            type: 'POST',
            data: {"status": cate,"currentPageNo":currentPageNo},
            dataType:'json',
            success: function (data) {
                var str="";
                var num = 0;
                /*$(data).each(function () {
                    var tim = addDate(this.createTime,this.time);
                    str="<tr class='tab-sum'>";
                    str="<td>"+this.type+"</td>";
                    str="<td>"+this.createTime+"</td>";
                    str="<td>"+tim+"</td>";
                    str="<td>"+this.sustainDate+"</td>";
                    str="<td>"+this.scope+"</td>";
                    str="</tr>";
                });*/
                /*for (var i in obj['list']){
                    var tim = addDate(obj['list'][i]['createTime'],obj['list'][i]['time']);
                    str="<tr class='tab-sum'>";
                    str="<td>"+obj['list'][i]['type']+"</td>";
                    str="<td>"+obj['list'][i]['createTime']+"</td>";
                    str="<td>"+tim+"</td>";
                    str="<td>"+obj['list'][i]['sustainDate']+"</td>";
                    str="<td>"+obj['list'][i]['scope']+"</td>";
                    str="</tr>";
                }*/
                for (var i of data.aqbInterests){
                    num = num + 1;
                    var tim = addDate(i.createTime,i.time);
                    var tim1 = new Date(i.createTime).Format("yyyy-MM-dd");
                    str +="<tr class='tab-sum'>";
                    str +="<td style='border:1px solid #c0c0c0'>"+i.type+"</td>";
                    str +="<td style='border:1px solid #c0c0c0'>"+tim1+"</td>";
                    str +="<td style='border:1px solid #c0c0c0'>"+tim+"</td>";
                    str +="<td style='border:1px solid #c0c0c0'>"+i.date+"</td>";
                    str +="<td style='border:1px solid #c0c0c0'>"+i.scope+"</td>";
                    str +="</tr>";
                }
                // addDate(i.createTime,0)top.dateFtt("yyyy-MM-dd",i.createTime)
                /*str +="<div class='page-bar'>";
                str +="<ul class='page-num-ul clearfix'>";
                str +="<li>共"+data.phs.totalCount+"条记录&nbsp;&nbsp;"+data.phs.currentPageNo+"/"+data.phs.totalPageCount+" 页</li>";
                str +="<a>首页</a>";
                str +="<a>上一页</a>";
                str +="<a>下一页</a>";
                str +="<a>最后一页</a>";
                str +="&nbsp;&nbsp";
                str +="</ul>";
                str +="<span class='page-go-form'><label>跳转至</label>";
                str +="<input type='text' name='inputPage' id='inputPage' class='page-key' />页";
                str +="<button type='button' class='page-btn'>GO</button>";
                str +="</span>";
                str +="</div>";*/
                $(".tab-sum").remove();
                $("#tab-zyf").append(str);
                $("#val-zyf").html(data.phs.totalCount);
                $(".zyf-totalCount").html(data.phs.totalCount);
                $(".zyf-currentPageNo").html(data.phs.currentPageNo);
                $(".zyf-totalPageCount").html(data.phs.totalPageCount);

                $("#sta").html(data.status);
                $("#name").html(data.phs.currentPageNo);
                $("#all").html(data.phs.totalPageCount);
                //$("#sta").attr("value",data.status).attr("name",data.phs.currentPageNo).attr("all",data.phs.totalPageCount);
                //$(".zyf-hidden").html("<input type='hidden' id='zyf-pageNo' value='"+data.phs.currentPageNo+"'/><input type='hidden' id='zyf-pageAll' value='"+data.phs.totalPageCount+"'/>");

                /*var obj = eval('(' + data + ')');
                var str = "";
                var dataStr = "";
                var qx = "";
                for (var i in obj['list']) {
                    total[cate]++;
                    if (cate == 1) {
                        str = "<div class='m2_ticresult_reword m2_ticresult_unuse'>";
                        $('#total' + cate).html('<i></i>累计可用加息卷：' + total[cate] + '个');
                    } else if (cate == 2) {
                        str = " <div class='m2_ticresult_reword m2_ticresult_hasused'>";
                        $('#total' + cate).html('<i></i>累计已使用加息卷：' + total[cate] + '个');
                    } else if (cate == 3) {
                        str = " <div class='m2_ticresult_reword m2_ticresult_endtime'>";
                        $('#total' + cate).html('<i></i>累计已过期加息卷：' + total[cate] + '个');
                    }

                    if (obj['list'][i]['allow_project_period'] == 1) {
                        qx = "·&nbsp;限投" + obj['list'][i]['allow_project_period'] + "个月项目";
                    } else if (obj['list'][i]['allow_project_period'] == 0) {

                    } else {
                        qx = "·&nbsp;限投" + obj['list'][i]['allow_project_period'] + "个月及以下项目";
                    }

                    dataStr += str + "<div class='packet_title'><span>" + obj['list'][i]['info'] + "</span>"
                        + "<span class='packet_where'>" + obj['list'][i]['allow_client_type'] + "</span></div><div class='packet_introduce_left'>"
                        + "<span class='number'>" + obj['list'][i]['percentage'] + "</span><span class='unit'>%</span></div>"
                        + "<div class='packet_introduce_right'><div class='packet_introduce_right_con'><p>" + qx + "</p><p>"
                        + "·&nbsp;投资额≥" + obj['list'][i]['use_condition'] + "元可使用</p></div><i></i></div><div class='packet_bottom'><span>起效期：" + obj['list'][i]['date1'] + "</span><span class='packet_endtime'>有效期至：" + obj['list'][i]['date2'] + "</span></div></div>";*/

                },
            error:function () {
                alert("sss");
            }

                /*$('#list' + cate).append(dataStr);
                if (obj['totalpage'] <= index[cate]) {
                    $('#loadmore' + cate).hide();
                }
                index[cate]++;
            }*/
        });

    }
    $(".zyf-first").click(function () {
        var cate = $("#sta").html();
        getMore(cate,1);
    });
    $(".zyf-prev").click(function () {
        var cate = $("#sta").html();
        var currentPageNo = $("#name").html()*1;
        var s= currentPageNo-1;
        if(s <= 0){
            s = 1;
        }
        getMore(cate,s);
    });
    $(".zyf-second").click(function () {
        var cate = $("#sta").html();
        var currentPageNo = $("#name").html()*1;
        var pageAll = $("#all").html()*1;
        if(currentPageNo+1 > pageAll){
            getMore(cate,pageAll);
        }else{
            getMore(cate,currentPageNo+1);
        }
    });
    $(".zyf-last").click(function () {
        var cate = $("#sta").html();
        var currentPageNo = $("#all").html()*1;
        getMore(cate,currentPageNo);
    });
    //跳转
    function jump_to(ddddd) {
        var cate = $("#sta").html();
        getMore(cate,ddddd);
    }

    //加息券兑换部分
    $('.m2-addConfirm-head i,.m2-addConbtn-can').click(function () {
        $('.m2-userCentercommon-bg,.m2-addConfirm').hide();
        // getMore(1,1);
    });
    $('.m2-ticketConfirmbtn').click(function () {
        $('#reward_code').val('');
        $('.m2-addConfir-psg').html('');
        $('.m2-addConbtn-can').text('取消');
        $('.m2-userCentercommon-bg,.m2-addConfirm').show();
        // getMore(1,1);
    });
    $('.m2-addConbtn-act').click(function () {
        var cate = $("#sta").html();
        $.ajax({
            url: '/zyf/conversion',
            data: {
                rewardcode: $('#reward_code').val()
            },
            dataType:"text",
            success: function (data) {
                var msg = '';
                if (data == "t") {
                    msg = '<i class="m2-addConfir-tur"></i>帮主加息券已激活成功!';
                    $('.m2-addConbtn-can').text('关闭');
                    // $('#list1').html('');
                    $('#loadmore1').show();
                    getMore(cate,1);
                } else {
                    msg = '<i class="m2-addConfir-fal"></i>';
                }
                $('.m2-addConfir-psg').html(msg);
                // getMore(1,1);
                /*var obj = eval('(' + data + ')');
                var msg = '';
                if (obj['status'] == 1) {
                    msg = '<i class="m2-addConfir-tur"></i>帮主加息券已激活成功!';
                    $('.m2-addConbtn-can').text('关闭');
                    index[1] = 1;
                    total[1] = 0;
                    $('#list1').html('');
                    $('#loadmore1').show();
                    getMore(1);
                } else {
                    msg = '<i class="m2-addConfir-fal"></i>' + obj['msg'];
                }
                $('.m2-addConfir-psg').html(msg);*/
            }
        });
        // getMore(cate,1);
    });


    /**
     * 时间戳格式化函数
     * ajax使用格式：new Date(i.createTime).Format("yyyy-MM-dd");
     */
    Date.prototype.Format = function (fmt) { //author: meizz
        var o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "h+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    }
</script>
</body>
</html>